package samsung.sds.resourceManagement.service.impl;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import samsung.sds.resourceManagement.dao.ResourceToRoleMapper;
import samsung.sds.resourceManagement.model.ResourceToRole;
import samsung.sds.resourceManagement.service.ResourceToRoleService;
import samsung.sds.system.common.baseQuery.AbstractBaseService;
import samsung.sds.system.common.baseQuery.BaseMapper;
/** 
 * @author pt.fang
 * @createDate 2016-02-18
 * 资源角色实例 实现类
 */
@Service
public class ResourceToRoleServiceImpl extends AbstractBaseService<ResourceToRole> implements ResourceToRoleService{

	@Autowired
	private ResourceToRoleMapper resourceToRoleMapper;
	
	@Override
	protected BaseMapper<ResourceToRole> getMapper() {
		return resourceToRoleMapper;
	}
	
	/**
	 * 通过资源ID查询角色列表
	 * @param id 资源ID
	 * @return
	 */
	@Override
	public List<ResourceToRole> selectSYS_ROLE_TO_RES(String id) {
		return resourceToRoleMapper.selectSYS_ROLE_TO_RES(id);
	}
	
	/**
	 * 通过资源ID删除角色
	 * @param id 资源ID
	 * @return
	 */
	@Override
	public int deleteEntityById(String id) {
		List<ResourceToRole> resourceToRoles = resourceToRoleMapper.selectSYS_ROLE_TO_RES(new String(id));
		if(resourceToRoles.size()==0){
			return -1;
		}else{
			for (ResourceToRole resourceToRole : resourceToRoles) {
				this.getMapper().deleteEntity(resourceToRole);
			}
		}
		return 1;
	}
}
